import request from './axios'

interface ManageRes<T> {
    code?: number
    data: T
    count?:number
    error?:number
    username:string
}
type PromiseRes<T = {}> = Promise<ManageRes<T>>
interface adminLoginRes {
  token:string
  avatar:string
}
interface adminLoginListRes{
  pk: string
  fields: {
    email: string
    nickname: string
    phone: string
    sign: string
    avatar: string
    age:number
    sex:number

  }
}
// interface goodsListRes{
//   g_id:string
//   c_id:string
//   g_name:string
//   g_img: string
//   g_price: number
//   g_info: string
//   g_count: number
// }

interface classAddListApiRes{
  c_name:string
  c_info:string
  c_parent_id: number
  level: string
}
interface addressListApiRes{
  city:string
  detail:string
  id:number
  name:string
  phone:string
  state:number
  username:string
}
// 用户
// 用户注册
export const userRegisterApi = (data: API.userRegisterData):PromiseRes<{}> => request.post('/user', data)
// 用户登录
export const userLoginApi = (data: API.userLoginData):PromiseRes<adminLoginRes> => request.post('/ulogin', data)
// 单个用户获取
export const userLoginOneApi = (username:string):PromiseRes<API.adminLoginOneRes> => request.get( `/admin/${username}`)
// 修改用户
export const userUpdataApi = (username:string,data:API.adminLoginOneRes):PromiseRes<API.adminLoginOneRes> => request.put( `/admin/${username}`, data)

// 分类
// 分类列表获取
export const classListApi = ():PromiseRes<API.classListRes[]> => request.get('/class')
// 单个分类列表获取
export const classListOneApi = (nid:number):PromiseRes<API.classListData> => request.get('/class/' + nid)
// 类id及名字获取
export const classParentIdListApi = (nid:number|string):PromiseRes<{c_id:number, c_name:string, level: number}[]> => request.get('/class/parentid/'+nid)


// 商品
export const goodsssListApi = (currentPage:number, pagesize:number,nid:string|null):PromiseRes<API.goodsOneRes[]> => request.get(`/goods/${nid}/ss_goods`, {params:{"currentPage":currentPage, "pagesize": pagesize}})
export const goodsflListApi = (currentPage:number, pagesize:number,nid:string|null):PromiseRes<API.goodsOneRes[]> => request.get(`/goods/${nid}/fl_goods`, {params:{"currentPage":currentPage, "pagesize": pagesize}})

export const goodsListApi = (currentPage:number, pagesize:number):PromiseRes<API.goodsOneRes[]> => request.get(`/goods`, {params:{"currentPage":currentPage, "pagesize": pagesize}})
// 单个分类列表获取
export const goodsListOneApi = (nid:number):PromiseRes<API.goodsOneRes> => request.get('/goods/' + nid)

// 添加购物车
export const ShoppingCartAddApi = (user_name:string|null,data:{good_id:number, shopping_cart_num:number}):PromiseRes<API.goodsOneRes[]> => request.post(`/Shoppingcart/${user_name}`,data)
// 获取购物车
export const ShoppingCartListApi = (user:string):PromiseRes<any[]> => request.get(`/Shoppingcart/${user}`)
// 修改购物车
export const ShoppingCartPutApi = (nid:number,data:any):PromiseRes<any[]> => request.put(`/Shoppingcart/${nid}`,data)
// 删除购物车
export const ShoppingCartDeleteApi = (nid:number):PromiseRes<any[]> => request.delete(`/Shoppingcart/${nid}`)


// 轮播图
export const bannerListApi = (currentPage:number, pagesize:number):PromiseRes<API.bannerOneRes[]> => request.get('/banner', {params:{"currentPage":currentPage, "pagesize": pagesize}})

// 地址
export const addressListApi = (username:string):PromiseRes<addressListApiRes[]> => request.get(`/address/${username}`)
// 单个查询
export const addressListOneApi = (username:string,id:number):PromiseRes<addressListApiRes> => request.get(`/address/${username}/${id}`)
// 添加
export const addressAddApi = (username:string,id:number,data:any):PromiseRes<{}> => request.post(`/address/${username}/${id}`,data)
// 修改
export const addressPutApi = (username:string,id:number,data:any):PromiseRes<{}> => request.put(`/address/${username}/${id}`,data)
// 删除
export const addressDelApi = (username:string,id:number):PromiseRes<addressListApiRes> => request.delete(`/address/${username}/${id}`)

// 订单
export const productOrderListApi = (user:string, state=5):PromiseRes<API.productOrderListRes[]> => request.get(`/product_order/${user}`,{params:{"state":state}})
export const productOrderIdApi = (id:number):PromiseRes<API.productOrderListRes[]> => request.get(`/product_order`,{params:{"id":id}})

// 添加
export const productOrderAddApi = (username:string,data:any):PromiseRes<{}> => request.post(`/product_order/${username}`,data)
// 购物车批量下单
export const productOrderListAddApi = (username:string,data:any):PromiseRes<{}> => request.post(`/product_order_list/${username}`,data)

// 修改
export const productOrderPutApi = (data:any):PromiseRes<{}> => request.put(`/product_order`,data)

